package com.wj.taobaoke;

import java.io.BufferedReader;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.List;

public class ReadTemplate {

	public List<String> templateStrList;
	public List<String> newsListStrList;
	public List<String> navStrList;
	
	public String projectPath;	

	public void readTemplateList(String templateFileName){
		projectPath = getClass().getProtectionDomain().getCodeSource().getLocation().getPath();
		projectPath = projectPath.substring(0, projectPath.indexOf("WEB-INF/classes"));
		templateStrList = new ArrayList<String>();
		newsListStrList = new ArrayList<String>();
		navStrList =new ArrayList<String>();
		String templateFilePath = projectPath + "common/" + templateFileName;
		FileReader fileReader = null;
		try {
			fileReader = new FileReader(templateFilePath);
			BufferedReader bufferedReader = new BufferedReader(fileReader);
			String temp;
			while ((temp = bufferedReader.readLine()) != null) {
				temp = temp.trim();
				if(temp.length() == 0){
					continue;
				}
				if(temp.startsWith("<!-- nav -->")){
					navStrList.add(temp.replace("<!-- nav -->", ""));
				}else if(temp.startsWith("<!--1-->")){
					newsListStrList.add(temp.replace("<!--1-->", ""));
				}else{
					templateStrList.add(temp);
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			try{
				if(fileReader != null){
					fileReader.close();
				}
			}catch (Exception e) {
				e.printStackTrace();
			}
		}
	}

	public String getProjectPath() {
		return projectPath;
	}

}
